package com.oj.auth.entity;

import com.oj.api.auth.domain.RoleInfo;
import com.oj.common.data.BaseEntity;
import lombok.*;

import javax.persistence.*;
import java.util.Set;

/**
 * Created by hu on 2018/5/11.
 */
@Entity(name = "AUTH_ROLE")
@Table(indexes = {
        @Index(name = "auth_idx_code_role",unique = true,columnList = "code")
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class RoleEntity extends BaseEntity<RoleInfo> {

    /**
     * 用户列表
     */
    @ManyToMany(cascade = CascadeType.REFRESH,fetch = FetchType.LAZY)
    @JoinTable(name="AUTH_RE_AE",joinColumns = @JoinColumn(name="RE_ID",referencedColumnName = "PK_ID"),
            inverseJoinColumns = @JoinColumn(name = "AE_ID",referencedColumnName = "PK_ID"))
    @OrderBy(value = "code")
    private Set<AccountEntity> users;

    @Override
    protected RoleInfo createInfo() {
        return new RoleInfo();
    }

    @Override
    public RoleInfo buildInfo(RoleInfo roleInfo) {
        super.buildInfo(roleInfo);
        return roleInfo;
    }
}
